package com.project.basis.model

import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
import com.project.basis.config.ProjectApplication

object ConfigDao {

    // 屏幕宽高
    private const val SCREEN_WIDTH = "SCREEN_WIDTH"
    private const val SCREEN_HEIGHT = "SCREEN_HEIGHT"

    // 用户id
    private const val USER_ID = "USER_ID"

    // 用户密码（MD5）
    private const val USER_PWD = "USER_PWD"

    private fun getSharedPreferences(): SharedPreferences {
        return ProjectApplication.context.getSharedPreferences("NaYuTaConfig", Context.MODE_PRIVATE)
    }

    fun setScreenWidth(screenWidth: Int) {
        getSharedPreferences().edit {
            putInt(SCREEN_WIDTH, screenWidth)
        }
    }

    fun getScreenWidth(): Int {
        return getSharedPreferences().getInt(SCREEN_WIDTH, 0)
    }

    fun setScreenHeight(screenHeight: Int) {
        getSharedPreferences().edit {
            putInt(SCREEN_HEIGHT, screenHeight)
        }
    }

    fun getScreenHeight(): Int {
        return getSharedPreferences().getInt(SCREEN_HEIGHT, 0)
    }

    fun setUserId(userId: String) {
        getSharedPreferences().edit {
            putString(USER_ID, userId)
        }
    }

    fun getUserId(): String {
        return getSharedPreferences().getString(USER_ID, "") ?: ""
    }

    fun setUserPwd(password: String) {
        getSharedPreferences().edit {
            putString(USER_PWD, password)
        }
    }

    fun getUserPwd(): String {
        return getSharedPreferences().getString(USER_PWD, "") ?: ""
    }
}